//
//  HETWOpraetionView.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/29.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HETWOpraetionView.h"

@interface HETWOpraetionView ()

@property (nonatomic, assign) HETWOpraetionType type;

@end

@implementation HETWOpraetionView

- (instancetype)initWithFrame:(CGRect)frame withType:(HETWOpraetionType)type {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = KWhiteColor;
        _type = type;
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    if (_type == HETWOpraetionTypeEnd) {
        [self initEndView];
    }
    else if (_type == HETWOpraetionTypeDocRefuse) {
        [self initRefuseView];
    }
    else if (_type == HETWOpraetionTypeWhetherEnd) {
        [self initWhetherEndView];
    }
}

// 过期或者结束的底部视图
- (void)initEndView {
    
    CGFloat endViewhHeight = 160;
    
    UILabel *endTitleLb = [UILabel new];
    endTitleLb.text = @"问诊已结束或已过期";
    endTitleLb.font = DYBlodFont(16);
    endTitleLb.textColor = COrangeColor;
    [self addSubview: endTitleLb];
    
    UILabel *endDescLb = [UILabel new];
    endDescLb.text = @"若已解决您的问题，欢迎您对我们的服务做出评价，若遇到问题，您可选择投诉。";
    endDescLb.numberOfLines = 0;
    endDescLb.font = DYBlodFont(15);
    endDescLb.textColor = CNavDargGrayColor;
    [self addSubview: endDescLb];

    QMUIFillButton *commentBtn = [[QMUIFillButton alloc] initWithFillColor:CNavBgColor titleTextColor:CNavBgFontColor];
    commentBtn.titleLabel.font = UIFontMake(16);
    [commentBtn setTitle:@"评价" forState:UIControlStateNormal];
    commentBtn.tag = 0;
    [self addSubview:commentBtn];
    [commentBtn addTarget:self action:@selector(commentClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [endTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(15);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];
    
    [endDescLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endTitleLb.mas_bottom).offset(15);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];
 
    [commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(200);
        make.height.offset(40);
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.mas_bottom).offset(-15);
    }];
}


// 医生拒绝
- (void)initRefuseView {
    
    UILabel *endTitleLb = [UILabel new];
    endTitleLb.text = @"医生拒接了您的咨询，您可前往订单页进行申请退款。若遇到问题，请您联系平台及时反馈。";
    endTitleLb.font = DYBlodFont(16);
    endTitleLb.textColor = COrangeColor;
    endTitleLb.numberOfLines = 0;
    [self addSubview: endTitleLb];
    
    QMUIFillButton *commentBtn = [[QMUIFillButton alloc] initWithFillColor:CNavBgColor titleTextColor:CNavBgFontColor];
    commentBtn.titleLabel.font = UIFontMake(16);
    [commentBtn setTitle:@"去退款" forState:UIControlStateNormal];
    commentBtn.tag = 0;
    [commentBtn addTarget:self action:@selector(refuedClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:commentBtn];

    [endTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.bottom.equalTo(commentBtn.mas_top).offset(-5);
    }];
    
    [commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(40);
        make.width.offset(200);
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.mas_bottom).offset(-15);
    }];
}

// 过期或者结束的底部视图
- (void)initWhetherEndView {
    
    CGFloat endViewhHeight = 160;
 
    UILabel *endTitleLb = [UILabel new];
    endTitleLb.text = @"是否结束问诊：";
    endTitleLb.font = DYBlodFont(16);
    endTitleLb.textColor = COrangeColor;
    [self addSubview: endTitleLb];
    
    UILabel *endDescLb = [UILabel new];
    endDescLb.text = @"感谢您的信任和支持，如结束咨询，请对我的服务进行评价。";
    endDescLb.numberOfLines = 0;
    endDescLb.font = DYBlodFont(15);
    endDescLb.textColor = CNavDargGrayColor;
    [self addSubview: endDescLb];
    
    QMUIGhostButton *continuBtn = [[QMUIGhostButton alloc] initWithGhostColor:CNavBgColor];
    continuBtn.titleLabel.font = UIFontMake(16);
    [continuBtn setTitle:@"继续问诊" forState:UIControlStateNormal];
    continuBtn.tag = 0;
    [self addSubview:continuBtn];

    QMUIFillButton *endBtn = [[QMUIFillButton alloc] initWithFillColor:CNavBgColor titleTextColor:CNavBgFontColor];
    endBtn.titleLabel.font = UIFontMake(16);
    [endBtn setTitle:@"结束问诊" forState:UIControlStateNormal];
    endBtn.tag = 1;
    [self addSubview:endBtn];
    
    [continuBtn addTarget:self action:@selector(continuClick:) forControlEvents:UIControlEventTouchUpInside];
    [endBtn addTarget:self action:@selector(endClick:) forControlEvents:UIControlEventTouchUpInside];
  
    [endTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(15);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];
    
    [endDescLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endTitleLb.mas_bottom).offset(15);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];

    NSArray *arr = @[continuBtn , endBtn];

    [arr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-15);
        make.height.offset(40);
    }];

    [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
}

#pragma mark  - click
// 评论
- (void)commentClick:(QMUIButton *)sender {
    if (self.operationBlock) {
        self.operationBlock(_type, sender.tag);
    }
}

// 拒绝
- (void)refuedClick:(QMUIButton *)sender {
    if (self.operationBlock) {
        self.operationBlock(_type, sender.tag);
    }
}

// 继续问诊
- (void)continuClick:(QMUIButton *)sender {
    if (self.operationBlock) {
        self.operationBlock(_type, sender.tag);
    }
}

// 结束问诊
- (void)endClick:(QMUIButton *)sender {
    if (self.operationBlock) {
        self.operationBlock(_type, sender.tag);
    }
}

//
- (void)operationActionHandler:(operationActionBlock)block {
    self.operationBlock = block;
}

@end
